import type {TinyUserInfo} from "./User.ts";

// 屏蔽配置
export class BlockConfig {
    // 屏蔽的关键字
    keywords: string[] = []
    // 屏蔽的用户
    users: TinyUserInfo[] = []

    constructor(text?: string | undefined) {
        if (!text) return
        const arr = text.split('\n');
        this.keywords = arr[1].split(' ')
        this.users = arr[2].split(' ').map(it => {
            const [userId, username] = it.split('/')
            return {
                userId: Number(userId),
                username
            }
        })
    }

    hasUser(userId: number | undefined) {
        return this.users.some(it => it.userId === userId)
    }

    toString(): string {
        return `1\n${this.keywords.join(' ')}\n${this.users.map(it => `${it.userId}/${it.username}`).join(' ')}`
    }
}